<template>
  <div>
    <h1>专业管理</h1>
    <el-table :data="subjectDate" border style="width: 100%">
      <el-table-column prop="_id" label="编号" width="180"> </el-table-column>
      <el-table-column prop="name" label="专业名" width="180"> </el-table-column>
          

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >修改</el-button
          >
             <el-button
          size="mini"
          type="danger"
      
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageDate.currentPage"
      :page-sizes="[1, 5, 8, 10]"
      :page-size="pageDate.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
import pageMixins  from '@/mixins/pageMixins.js'
const { mapActions: subjectActions, mapState: subjectState } =
  createNamespacedHelpers("subject");
export default {
  mixins:[pageMixins],
  created() {
    this.getSubjectList();

  },
  methods: {
      ...subjectActions(['getSubjectAsync']),
      ...subjectActions(['delSubjectAsync']),
    
    getSubjectList() {
      this.getSubjectAsync(this.pageDate);
    },
     
    // 修改
       handleEdit(index, row) {
          this.$router.push('/home/subjectSUpdate/'+row._id)
       
      },
    async  handleDelete(index,row){
          const data=     await  this.delSubjectAsync({_id:row._id})
              if(data.code){
                 this.$message({
                message: '删除成功',
                type: 'success'
                 })
                this.getSubjectList()
              }else{
                alert(data.message)
              }
      }
       

  },
  computed: {
    ...subjectState({
      subjectDate: "rows",
      pages: "pages",
      total: "total",
    }),
  },
  watch: {
    pageDate: {
      handler() {
      
        this.getSubjectList();
      },
      deep: true,
    },
  },

};
</script>

<style>
</style>